﻿var item_tpl = Handlebars.compile($('#item_template').html());
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
    WeixinJSBridge.call('hideToolbar');
});

$(function () {
    var $main = $('#main');
    var url = $main.attr('data-url');
    var ctx = $main.attr('data-ctx');


    $.get(url, function (rst) {
        if (rst.status == 'OK') {
            var data = rst.data;
            $.each(data,function (idx, val) {
                var remark = val.remark;
                val['remark'] = (remark && remark.length > 40) ? remark.substring(0,38) + "..." : remark;
                val['end_time'] = val.end_time.substring(0,10);
                var each_data = item_tpl(val);
                $main.append(each_data);
            });

        }
    });
    var mid = $("#mid").val();
    var wxno = $("#wxno").val();

    $main.on('click', '.item-list', function () {
        var itemUrl = $(this).attr('data-url');
        itemUrl = itemUrl + '&mid=' + mid + '&wxno=' + wxno;
        window.location.href = itemUrl;
    });
});
